//
//  DD_RootViewController.m
//  mhkjjsd
//
//  Created by 凤利史 on 2018/5/22.
//  Copyright © 2018年 sunrose. All rights reserved.
//

#import "DD_RootViewController.h"
#import "DD_RootTableViewCell.h"
@interface DD_RootViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;

Strong UITextField *yuYueTextField;//预约
Strong UILabel *ddddLab;//导流订单
Strong UILabel *yyddLab;//预约订单
Strong UILabel *wcddLab;//完成订单
Strong UIView *blueView;//蓝色条
Strong UIButton *yYDDBtn;//预约订单
Strong UIButton *dlddBtn;//导流订单
Strong UIButton *wcddBtn;//完成订单
Strong NSArray *arrDay;


@end

@implementation DD_RootViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _arrDay = @[@"日", @"一", @"二", @"三", @"四", @"五", @"六"];
    [self creationView];
    [self creationDayView];
    [self regeditCell];
    
    // Do any additional setup after loading the view.
}
- (void)creationView{
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [self.view addSubview:titleLabel];
    titleLabel.text = @"阿三老师客户端";
    titleLabel.textColor = getColor(@"333333");
    titleLabel.font = [UIFont fontWithName:@"DINEngschrift LT Alternate" size:17];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(15);
        make.top.equalTo(self.view).with.offset((KIsiPhoneX?24:0)+20);
 
    }];
    UIView *findView = [[UIView alloc] init];
    [self.view addSubview:findView];
    [findView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(15);
        make.top.equalTo(titleLabel.mas_bottom).with.offset(19);
        make.right.equalTo(self.view).with.offset(-15);
        make.height.offset(35);

    }];
    findView.backgroundColor = getColor(@"F2F2F2");
    findView.layer.cornerRadius = 4.0f;
    findView.layer.masksToBounds = YES;
    
    UIImageView *souSuoImgView = [[UIImageView alloc] init];
    [findView addSubview:souSuoImgView];
    UIImage *img = [UIImage imageNamed:@"home_search_icon"];
    [souSuoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(findView).with.offset(15);
        make.centerY.equalTo(findView);
        make.width.offset(img.size.width);
        make.height.offset(img.size.height);
        
    }];
    souSuoImgView.image = [UIImage imageNamed:@"home_search_icon"];
    
    self.yuYueTextField = [[UITextField alloc] init];
    [findView addSubview:self.yuYueTextField];
    [self.yuYueTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(souSuoImgView.mas_right).with.offset(5);
        make.right.equalTo(findView).with.offset(-15);
        make.centerY.equalTo(findView);
        ;
    }];
    self.yuYueTextField.placeholder = @"查找预约";
//    self.yuYueTextField.textColor = getColor(@"999999");
    self.yuYueTextField.font = [UIFont systemFontOfSize:14];
    /////新卡
    UIButton *xinKaBtn = [[UIButton alloc] init];
    UIImage *xinKaImg = [UIImage imageNamed:@"home_vip_btn"];
    [self.view addSubview:xinKaBtn];
    [xinKaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(23);
        make.top.equalTo(findView.mas_bottom).with.offset(15);
        make.width.offset(xinKaImg.size.width);
        make.height.offset(xinKaImg.size.height);
        
    }];
    [xinKaBtn setBackgroundImage:xinKaImg forState:UIControlStateNormal];
    
    UILabel *xinKaLab = [[UILabel alloc] init];
    [self.view addSubview:xinKaLab];
    [xinKaLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(xinKaBtn.mas_bottom).with.offset(10);
        make.centerX.equalTo(xinKaBtn);
    }];
    xinKaLab.text = @"新卡";
    xinKaLab.font = [UIFont systemFontOfSize:14];
    xinKaLab.textColor = getColor(@"333333");
    
    //扫码
    UIButton *saoMaBtn = [[UIButton alloc] init];
    [self.view addSubview:saoMaBtn];
    [saoMaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
     
        make.left.equalTo(xinKaBtn.mas_right).with.offset((DEF_SCREEN_WIDTH - 46 - 4 * xinKaImg.size.width)/3);
        make.top.equalTo(findView.mas_bottom).with.offset(15);
        
    }];
    [saoMaBtn setBackgroundImage:[UIImage imageNamed:@"home_scanning_btn"] forState:UIControlStateNormal];
    
    UILabel *saoMaLab = [[UILabel alloc] init];
    [self.view addSubview:saoMaLab];
    [saoMaLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(saoMaBtn.mas_bottom).with.offset(10);
        make.centerX.equalTo(saoMaBtn);
    }];
    saoMaLab.text = @"扫码";
    saoMaLab.font = [UIFont systemFontOfSize:14];
    saoMaLab.textColor = getColor(@"333333");
    
    //下单
    UIButton *xiaDanBtn = [[UIButton alloc] init];
    [self.view addSubview:xiaDanBtn];
    [xiaDanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(saoMaBtn.mas_right).with.offset((DEF_SCREEN_WIDTH - 46 - 4 * xinKaImg.size.width)/3);
        make.top.equalTo(findView.mas_bottom).with.offset(15);
        
    }];
    [xiaDanBtn setBackgroundImage:[UIImage imageNamed:@"home_order_btn"] forState:UIControlStateNormal];
    
    UILabel *xiaDanLab = [[UILabel alloc] init];
    [self.view addSubview:xiaDanLab];
    [xiaDanLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(xiaDanBtn.mas_bottom).with.offset(10);
        make.centerX.equalTo(xiaDanBtn);
    }];
    xiaDanLab.text = @"下单";
    xiaDanLab.font = [UIFont systemFontOfSize:14];
    xiaDanLab.textColor = getColor(@"333333");
    
    //商品
    UIButton *shangPinBtn = [[UIButton alloc] init];
    [self.view addSubview:shangPinBtn];
    [shangPinBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).with.offset(-23);
        make.top.equalTo(findView.mas_bottom).with.offset(15);
        
    }];
    [shangPinBtn setBackgroundImage:[UIImage imageNamed:@"home_commodity_btn"] forState:UIControlStateNormal];
    
    UILabel *shangPinLab = [[UILabel alloc] init];
    [self.view addSubview:shangPinLab];
    [shangPinLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(shangPinBtn.mas_bottom).with.offset(10);
        make.centerX.equalTo(shangPinBtn);
    }];
    shangPinLab.text = @"商品";
    shangPinLab.font = [UIFont systemFontOfSize:14];
    shangPinLab.textColor = getColor(@"333333");
    
    UIView *jianGeView = [[UIView alloc] init];
    [self.view addSubview:jianGeView];
    [jianGeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.offset(10);
        make.top.equalTo(xinKaLab.mas_bottom).with.offset(15);
        
    }];
    jianGeView.backgroundColor = getColor(@"F5F7FA");
////////预约订单
    _yYDDBtn = [[UIButton alloc] init];
    [self.view addSubview:_yYDDBtn];
    [_yYDDBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(15);
        make.top.equalTo(jianGeView.mas_bottom).with.offset(15);
    }];
    [_yYDDBtn setTitle:@"预约订单" forState:UIControlStateNormal];
    _yYDDBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_yYDDBtn setTitleColor:getColor(@"3296FB") forState:UIControlStateNormal];
    
    [_yYDDBtn addTarget:self action:@selector(yuYueDDClick:) forControlEvents:UIControlEventTouchUpInside];
    _yYDDBtn.tag = 10001;
    
    
    _yyddLab = [[UILabel alloc] init];
    [self.view addSubview:_yyddLab];
    [_yyddLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_yYDDBtn.mas_right).with.offset(3);
        make.centerY.equalTo(_yYDDBtn);
        make.height.offset(12);
        make.width.offset(12);
        
    }];
    _yyddLab.layer.cornerRadius = 6;
    _yyddLab.layer.masksToBounds = YES;
    _yyddLab.text = @"3";
    _yyddLab.textColor = [UIColor whiteColor];
    _yyddLab.backgroundColor = [UIColor redColor];
    _yyddLab.font = [UIFont systemFontOfSize:10];
    _yyddLab.textAlignment = NSTextAlignmentCenter;
//////////////倒流订单
    _dlddBtn = [[UIButton alloc] init];
    [self.view addSubview:_dlddBtn];
    [_dlddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(jianGeView.mas_bottom).with.offset(15);
    }];
    [_dlddBtn setTitle:@"导流订单" forState:UIControlStateNormal];
    _dlddBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    
    [_dlddBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    
    [_dlddBtn addTarget:self action:@selector(daoliuDDClick:) forControlEvents:UIControlEventTouchUpInside];
    _dlddBtn.tag = 10002;
    
    _ddddLab = [[UILabel alloc] init];
    [self.view addSubview:_ddddLab];
    [_ddddLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_dlddBtn.mas_right).with.offset(3);
        make.centerY.equalTo(_dlddBtn);
        make.height.offset(12);
        make.width.offset(12);
        
    }];
    _ddddLab.layer.cornerRadius = 6;
    _ddddLab.layer.masksToBounds = YES;
    _ddddLab.text = @"3";
    _ddddLab.textColor = [UIColor whiteColor];
    _ddddLab.backgroundColor = [UIColor redColor];
    _ddddLab.font = [UIFont systemFontOfSize:10];
    _ddddLab.textAlignment = NSTextAlignmentCenter;
/////////////完成订单
    _wcddBtn = [[UIButton alloc] init];
    [self.view addSubview:_wcddBtn];
    [_wcddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).with.offset(-15);
        make.top.equalTo(jianGeView.mas_bottom).with.offset(15);
    }];
    [_wcddBtn setTitle:@"完成订单" forState:UIControlStateNormal];
    
    _wcddBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_wcddBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    [_wcddBtn addTarget:self action:@selector(wanchengDDClick:) forControlEvents:UIControlEventTouchUpInside];
    _wcddBtn.tag = 10002;
    self.blueView = [[UIView alloc] init];
    [self.view addSubview:self.blueView];
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_yYDDBtn.mas_bottom).with.offset(14);
        make.centerX.equalTo(_yYDDBtn);
        make.width.offset(30);
        make.height.offset(1);
    }];
    self.blueView.backgroundColor = getColor(@"3296FB");
    
    UIView *huiView = [[UIView alloc] init];
    [self.view addSubview:huiView];
    [huiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_yYDDBtn.mas_bottom).with.offset(15);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.offset(1);
        
    }];
    huiView.backgroundColor = getColor(@"F5F7FA");
    
    
    
    
    
    
    
}

#pragma mark - 日期选择
- (void)creationDayView{
    UIView *dayView = [[UIView alloc] init];
    [self.view addSubview:dayView];
    [dayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(self.blueView.mas_bottom).with.offset(1);
        make.height.offset(50);
    }];
    CGFloat wth = ((DEF_SCREEN_WIDTH - 30) - 210)/6;
    for (int i = 0; i < _arrDay.count; i++) {
        UIButton *dayBtn = [[UIButton alloc] init];
        [dayView addSubview:dayBtn];
        dayBtn.frame = CGRectMake(15 + wth * i + 30 * i, 10, 30, 30);
        
       // dayBtn.backgroundColor = [UIColor whiteColor];
        
    
        if (i == 1) {
            
            dayBtn.backgroundColor = getColor(@"3296FB");
            [dayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            
        }else{
            dayBtn.backgroundColor = [UIColor whiteColor];
            [dayBtn setTitleColor:getColor(@"999999") forState:UIControlStateNormal];
        }
        
        [dayBtn setTitle:_arrDay[i] forState:UIControlStateNormal];
        
        [dayBtn addTarget:self action:@selector(dayClick:) forControlEvents:UIControlEventTouchUpInside];
        dayBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        dayBtn.layer.cornerRadius = 4.0f;
        dayBtn.layer.masksToBounds = YES;
        dayBtn.tag = 1000 + i;
        
    }
    UIView *view = [[UIView alloc] init];
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(dayView.mas_bottom);
        make.height.offset(5);
    }];
    view.backgroundColor = getColor(@"F5F7FA");
    
    
    self.tableView = [[UITableView alloc] init];
    
    self.tableView.frame = CGRectMake(0, (KIsiPhoneX?24:0) + 317, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 49 - (KIsiPhoneX?24:0) - 317);
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    
}

/////预约订单
- (void)yuYueDDClick:(UIButton *)sender{
    
    [_yYDDBtn setTitleColor:getColor(@"3296FB") forState:UIControlStateNormal];
    [_dlddBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    [_wcddBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    [self.blueView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_yYDDBtn.mas_bottom).with.offset(14);
        make.centerX.equalTo(_yYDDBtn);
        make.width.offset(30);
        make.height.offset(1);
        
    }];
    
    
}
//导流订单
- (void)daoliuDDClick: (UIButton *)sender{
    
    [_dlddBtn setTitleColor:getColor(@"3296FB") forState:UIControlStateNormal];
    [_yYDDBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    [_wcddBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    [self.blueView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_dlddBtn.mas_bottom).with.offset(14);
        make.centerX.equalTo(_dlddBtn);
        make.width.offset(30);
        make.height.offset(1);
        
    }];
    
}
//完成订单
- (void)wanchengDDClick:(UIButton *)sender{
    
    [_dlddBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    [_yYDDBtn setTitleColor:getColor(@"666666") forState:UIControlStateNormal];
    [_wcddBtn setTitleColor:getColor(@"3296FB") forState:UIControlStateNormal];
    [self.blueView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_wcddBtn.mas_bottom).with.offset(14);
        make.centerX.equalTo(_wcddBtn);
        make.width.offset(30);
        make.height.offset(1);
        
    }];
    
    
    
}

#pragma mark -- 选择时间
- (void)dayClick:(UIButton *)sender{
    

    
    for (int i = 0; i < _arrDay.count; i++) {
        if (sender.tag == 1000 + i) {
            sender.selected = YES;
            sender.backgroundColor = getColor(@"3296FB");
            [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            NSLog(@"%@", _arrDay[i]);
            continue;
        }
        UIButton *but = (UIButton*)[self.view viewWithTag:i + 1000];
        but.selected = NO;
        but.backgroundColor = [UIColor whiteColor];
        [but setTitleColor:getColor(@"999999") forState:UIControlStateNormal];
    }

    
    //  sender.selected = !sender.selected;
    //    if (sender.selected) {
    //        sender.backgroundColor = getColor(@"3296FB");
    //    }else{
    //
    //        sender.backgroundColor = [UIColor whiteColor];
    //    }
    
}
- (void)regeditCell{
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"DD_RootTableViewCell" bundle:nil] forCellReuseIdentifier:@"DD_RootTableViewCell"];
    
}

#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 22;
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 183;
    
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DD_RootTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"DD_RootTableViewCell" forIndexPath:indexPath];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
    
    
}

#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
